{
  "properties" : { },
  "id" : "1851d968675a4a45a620d2cc71861310",
  "script" : null,
  "groupId" : "bcdec4ef1ba74815bea2c09a20056b65",
  "name" : "删除",
  "createTime" : 1714063371759,
  "updateTime" : 1711898412485,
  "lock" : null,
  "createBy" : "管理员",
  "updateBy" : "管理员",
  "path" : "remove",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ {
    "name" : "permission",
    "value" : "system:uhgl",
    "description" : "允许拥有该权限的访问",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "requestBody" : "{\"ids\":[1002],\"unitId\":16}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : null,
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : null
}
================================
import com.gitee.fastmybatis.core.query.Query;
import 'com.wiwf.model.security.service.SysUserService' as userService;
import 'com.wiwf.model.security.service.SysTokenService' as sysTokenService;
import 'com.wiwf.model.mapper.admin.dao.SysUnitUserRoleMapper' as sysUnitUserRoleMapper;

var userId = sysTokenService.getTokenUser().getUserId();

if(body.unitId == 1){
    // 不能删除自己
    for (id in body.ids) {
        if(userId.equals(id)){
            exit 409, "不能删除自己";
        }
    }
    // 如果是在默认单位就
    for (userId in body.ids) {
        // 清除 所有关联
        Query query = new Query().eq('user_id', userId);
        sysUnitUserRoleMapper.deleteByQuery(query, null);
    }
    // 删除
    return userService.deleteByIds(body.ids);
} else {
    // 如果不是
    for (userId in body.ids) {
        // 清除 关联
        Query query = new Query().eq('unit_id', body.unitId).eq('user_id', userId);
        sysUnitUserRoleMapper.deleteByQuery(query, null);
    }
    return 0;
}